<template>
  <div>
    <div class="cbody">
      <div class="top">
        <div :class="dayChange == 0 ? 'hac' : ''" @click="setDays(0)">全部</div>
        <div :class="dayChange == 1 ? 'hac' : ''" @click="setDays(1)">今日</div>
        <div :class="dayChange == 2 ? 'hac' : ''" @click="setDays(2)">近7天</div>
        <div :class="dayChange == 3 ? 'hac' : ''" @click="setDays(3)">近30天</div>
      </div>
      <div class="info">
        <div class="head">
          <div>
            <div class="count">￥{{money.pt.toFixed(2)}}</div>
            <div class="name">合伙人收入</div>
          </div>
          <div>
            <div class="count">{{money.hh}}</div>
            <div class="name">合伙人数量</div>
          </div>
          <div>
            <div class="count">￥{{money.fw.toFixed(2)}}</div>
            <div class="name">账户余额</div>
          </div>
          <div>
            <div class="count">￥{{money.yj.toFixed(2)}}</div>
            <div class="name">已提现金额</div>
          </div>
        </div>
        <div class="parchange">
          <div :class="params.ord== 1 ? 'aced' : ''" @click="setType(1)">默认</div>
          <div :class="params.ord== 2 ? 'aced' : ''" @click="setType(2)">收入</div>
          <div :class="params.ord== 3 ? 'aced' : ''" @click="setType(3)">提现</div>
          <div :class="params.ord== 4 ? 'aced' : ''" @click="setType(4)">余额</div>
        </div>
          <el-table :data="list" stripe style="width: 100%">
            <el-table-column prop="partner_name" label="合伙人名称" align="center" width="380"></el-table-column>
            <el-table-column label="合伙人收入" align="center">
              <template slot-scope="scope">
                <span>￥ {{ scope.row.shou.toFixed(2)}}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="已提现金额">
              <template slot-scope="scope">
                <span>￥ {{ scope.row.ti.toFixed(2)}}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="账户余额">
              <template slot-scope="scope">
                <span>￥ {{ scope.row.balance.toFixed(2)}}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="平台佣金">
              <template slot-scope="scope">
                <span>￥ {{ scope.row.commission.toFixed(2)}}</span>
              </template>
            </el-table-column>

            <el-table-column align="center" label="操作">
              <template slot-scope="scope">
                <el-button
                  v-if="roleList.search('财务管理') != '-1'"
                  @click="details(scope.row.id)"
                  type="primary"
                  size="mini"
                  round
                >收入明细</el-button>
              </template>
            </el-table-column>
          </el-table>

        <div style="padding: 50px 0;text-align: center;">
          <el-pagination
            style="margin:0 auto"
            class="el-pagination"
            background
            layout="prev, pager, next"
            :page-count="pageTotal"
            @current-change="changePage"
          ></el-pagination>
        </div>
      </div>
    </div>
    <el-dialog title="收入明细" :visible.sync="showMx">
      <el-table :data="detailsList" stripe style="width: 100%">
        <el-table-column prop="title" label="活动名称"></el-table-column>
        <el-table-column prop="price" label="报名费用（元）">
          <template slot-scope="scope">{{ scope.row.price.toFixed(2)}}</template>
        </el-table-column>

        <el-table-column prop="bi" label="门店分成比例">
          <template slot-scope="scope">{{ scope.row.bi}}%</template>
        </el-table-column>
        <el-table-column prop="ping" label="平台佣金（元）">
          <template slot-scope="scope">{{ scope.row.ping.toFixed(2)}}</template>
        </el-table-column>
        <el-table-column prop="mendian" label="门店分成金额（元）">
          <template slot-scope="scope">{{ scope.row.mendian.toFixed(2)}}</template>
        </el-table-column>
        <el-table-column prop="time" label="结算时间">
          <template slot-scope="scope">{{ new Date ( scope.row.time ).toLocaleDateString () }}</template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="el-pagination"
        background
        layout="prev, pager, next"
        :page-count="detailsTotal"
        @current-change="detailsChangePage"
      ></el-pagination>
    </el-dialog>
  </div>
</template>
<script>
import Global from "../tool/Global.vue";
import axios from "axios";
import qs from "qs"; // 将请求转换成form 表单提交形式
export default {
  created() {
    this.getFinList();
    this.getTotal();
    this.getRole();
  },
  data() {
    return {
      loading: false,
      list: [],
      params: {
        ord: 1,
        limit: 10,
        page: 1
      },
      money: {
        pt: 0,
        hh: 0,
        fw: 0,
        yj: 0
      },
      info: {},
      dayChange: 0,
      types: "",
      detailsList: [],
      detailsTotal: 1,
      detailsId: "",
      pageTotal: 1,
      detailsPage: {
        page: 1
      },
      roleList: "",
      showMx: false
    };
  },
  methods: {
    /**
     *  获取权限
     */
    getRole: function() {
      let that = this;
      axios({
        method: "post",
        url: `${that.$store.state.url}/sysPermission/selectByEmployeeId`,
        data: qs.stringify({
          empId: that.$cookie.get("pid")
        })
      }).then(res => {
        console.log(res);
        let arr = res.data.data;
        let role = [];
        for (let i = 0; i < arr.length; i++) {
          role.push(arr[i].name);
        }
        this.roleList = role.toString();
      });
    },
    changePage(argv) {
      this.params.page = argv;
      this.getFinList();
    },
    detailsChangePage(argv) {
      this.detailsPage.page = argv;
      this.getDetails();
    },
    // 获取弹窗信息
    getDetails(id) {
      axios
        .post(
          `${this.$store.state.url}/tWithdrawal/selectDateilByPartner`,
          // qs.stringify ({
          //   id: 2
          // })
          qs.stringify({
            partnerId: this.detailsId,
            page: this.detailsPage.page,
            limit: 10
          })
        )
        .then(response => {
          let res = response.data;
          if (res.code == 0) {
            this.detailsList = res.data;
          }
        });
    },

    // 显示详情弹窗
    details(id) {
      let _this = this;
      this.detailsId = id;
      this.getDetails();
      this.showMx = true;
    },

    getTotal() {
      axios
        .post(
          `${this.$store.state.url}/tWithdrawal/selectMoneyByPartner`,
          qs.stringify({
            type: 2
          })
        )
        .then(response => {
          let res = response.data;
          if (res.code == 0) {
            this.info = res.data;
            this.setDays(0);
          }
        });
    },
    /**
     * 设置状态
     */
    setType: function(num) {
      this.params.ord = num;
      this.getFinList();
    },
    /**
     *  设置天数
     */
    setDays: function(num) {
      let that = this;
      that.dayChange = num;
      switch (num) {
        case 0:
          that.money = {
            pt: that.info.totalPrice,
            hh: that.info.partnerNum,
            fw: that.info.partnerTotalPrice,
            yj: that.info.backstageTotalPrice
          };
          break;
        case 1:
          that.money = {
            pt: that.info.totalTodayPrice,
            hh: that.info.partnerTodayNum,
            fw: that.info.partnerTodayTotalPrice,
            yj: that.info.backstageTodayTotalPrice
          };
          break;
        case 2:
          that.money = {
            pt: that.info.totalWeekPrice,
            hh: that.info.partnerWeekNum,
            fw: that.info.partnerWeekTotalPrice,
            yj: that.info.backstageWeekTotalPrice
          };
          break;
        case 3:
          that.money = {
            pt: that.info.totalMonPrice,
            hh: that.info.partnerMonNum,
            fw: that.info.partnerMonTotalPrice,
            yj: that.info.backstageMonTotalPrice
          };
          break;
      }
      console.log(that.money);
    },
    search() {
      this.getFinList();
    },
    /**
     *  查询财务列表
     */
    getFinList: function(num) {
      // let that = this;
      this.loading = true;
      let _this = this;
      axios
        .post(
          // `${this.$store.state.url}/tWithdrawal/selectDrawal`,
          `${this.$store.state.url}/tWithdrawal/selectByWithList`,
          qs.stringify(this.params)
        )
        .then(
          response => {
            let res = response.data;
            if (res.code == 0) {
              _this.pageTotal = Math.ceil(res.count / 10);
              _this.list = res.data;
            }
            this.loading = false;
          },
          () => {
            this.loading = false;
          }
        );
    },
    /*
     * 根据时间毫秒数 返回年月日
     */
    setDate: function(str) {
      let times = new Date(str);
      return `${times.getFullYear()}-${
        times.getMonth() < 10 ? "0" + times.getMonth() : times.getMonth()
      }-${times.getDate() < 10 ? "0" + times.getDate() : times.getDate()}`;
    },
    /**
     * 根据时间毫秒数 返回时分秒
     */
    setTime: function(str) {
      let times = new Date(str);
      return `${
        times.getHours() < 10 ? "0" + times.getHours() : times.getHours()
      }:${
        times.getMinutes() < 10 ? "0" + times.getMinutes() : times.getMinutes()
      }:${
        times.getSeconds() < 10 ? "0" + times.getSeconds() : times.getSeconds()
      }`;
    }
  },
  mounted() {}
};
</script>
<style scoped>
.el-pagination {
  text-align: center;
}
.parchange {
  /* width: 1520px; */
  height: 40px;
  line-height: 60px;
  font-family: PingFangSC-Medium;
  margin-top: 10px;
  margin-bottom: 10px;
  font-size: 14px;
  color: #778ca2;
  padding-left: 24px;
  box-sizing: border-box;
}
.parchange {
  padding: 0;
}
.parchange > div {
  display: inline-block;
  width: 110px;
  height: 26px;
  text-align: center;
  border-right: 1px solid #ddd;
  line-height: 26px;
  margin-top: 12px;
  cursor: pointer;
}
.parchange > div:last-of-type {
  height: 40px;
  margin-top: 0;
  line-height: 40px;
  border: 0px;
}
.parchange .aced {
  color: #085dab;
}
.screen img {
  float: left;
  width: 27px;
  height: 27px;
  margin-left: 10px;
  margin-top: 16px;
  margin-right: 18px;
}
.sel {
  height: 40px;
  line-height: 40px;
  width: 1520px;
}
.sel > span {
  font-weight: bold;
  font-size: 18px;
  color: #000000;
  float: left;
}
.sel > span:last-of-type {
  margin-left: 106px;
}
.sel > input {
  background: #ffffff;
  border: 1px solid #979797;
  box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.5);
  width: 317px;
  height: 38px;
  font-size: 18px;
  color: #888888;
  text-align: center;
  float: left;
  outline: none;
}
.sel > select {
  background: #ffffff;
  border: 1px solid #979797;
  box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.5);
  width: 317px;
  height: 38px;
  font-size: 18px;
  color: #888888;
  text-align: center;
  float: left;
  outline: none;
  padding-left: 70px;
}
.sel-btn {
  background: #085dab;
  border: 1px solid #085dab;
  width: 140px;
  height: 38px;
  font-size: 18px;
  color: #ffffff;
  text-align: center;
  float: left;
  margin-left: 50px;
  cursor: pointer;
}
.top {
  /* margin-top: 7px; */
  height: 40px;
  text-align: center;
  width: 440px;
  color: #778ca2;
  border-radius: 4px;
  display: flex;
  box-sizing: border-box;
}
.top > div {
  flex: 1;
  /* height: 40px; */
  line-height: 40px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  box-sizing: border-box;
}
.top :first-child {
  border: 0;
}
.top .hac {
  color: #4d7cfe;
  border-bottom: 2px solid #4d7cfe;
}
.head {
  margin-top: 20px;
  display: flex;
}
.head > div {
  flex: 1;
  height: 98px;
  background: rgba(255, 255, 255, 1);
  border-radius: 4px;
  display: inline-block;
  margin: 0 10px;
}
.head :first-child {
  margin: 0;
}
.name {
  font-size: 14px;
  color: #252631;
  height: 24px;
  text-align: center;
}
.count {
  height: 50px;
  font-size: 22px;
  color: #4b74ff;
  text-align: center;
  line-height: 50px;
  margin-top: 15px;
}
</style>


